package com.hmall.search.mq;

import com.hmall.search.constants.MqConstants;
import com.hmall.search.service.IsearchService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author Azer
 * @LOVE,,,
 * @Date 2021/11/8 11:47
 */
@Component
public class ItemListener {
    @Autowired
    private IsearchService service;

    /**
     * 监听商品上架
     */
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = MqConstants.Item_INSERT_QUEUE),
//            exchange = @Exchange(name = MqConstants.Item_EXCHANGE,
//                    type = ExchangeTypes.TOPIC),
//            key = MqConstants.Item_INSERT_KEY
//
//    ))
    @RabbitListener(queues = MqConstants.Item_INSERT_QUEUE)
    public void ListenItemInsert(Long id) throws IOException {
        service.ListenItemInsert(id);
    }


    /**
     * 监听商品下架
     */
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = MqConstants.Item_DELETE_QUEUE),
//            exchange = @Exchange(name = MqConstants.Item_EXCHANGE,
//                    type = ExchangeTypes.TOPIC),
//            key = MqConstants.Item_DELETE_KEY
//
//    ))
    @RabbitListener(queues = MqConstants.Item_DELETE_QUEUE)
    public void ListenItemDelete(Long id) throws IOException {
        service.ListenItemDelete(id);
    }
}
